#ifndef _MYSQL_RESULTSET_H_
#define _MYSQL_RESULTSET_H_

#include <string>
#include <stdint.h>
#include "../../../3rd/mysql/include/mysql.h"

namespace sql
{

	class ResultSet
	{
	private:
		MYSQL_RES *mMysqlResult;
		uint32_t mRowCount;
		uint32_t mLowCount;
		uint32_t mCurRow;
		unsigned long* mMysqlLowLength;

		MYSQL_ROW mMysqlRow;

		char* mValue;
		uint32_t mValueLength;
		uint32_t mValueLengthMax;

	public:
		ResultSet( );
		~ResultSet( );

		void Free( );
		int Init( MYSQL* mysql );
		bool IsUsing( );
		void close( );

		bool next( );

		const char* GetValue( uint32_t columnIndex );
		const char* GetValue( const char* name );

		int getInt( uint32_t columnIndex );
		int getInt( const char* name );

		long long getInt64( uint32_t columnIndex );
		long long getInt64( const char* name );

		uint32_t getUInt( uint32_t columnIndex );
		uint32_t getUint( const char* name );

		const char* getStringStr( uint32_t columnIndex );
		const char* getStringStr( const char* name );

		std::string getString( uint32_t columnIndex );
		std::string getString( const char* name );

		const char* getBlob( uint32_t columnIndex );
		const char* getBlob( const char* name );

		uint32_t findColumn( const char* name );
		const char* getFieldNameByCol( uint32_t column );
		enum enum_field_types getColTypes( uint32_t column );
		unsigned int getFieldLengthByCol( uint32_t column );

		uint32_t GetValueLength( ) { return mValueLength; }
	public:
		MYSQL_FIELD* GetField( uint32_t index )
		{
			return mysql_fetch_field_direct( mMysqlResult, index - 1 );
		}
		const char* setValue( const char* value, uint32_t value_length );
		void freeValue( );
	public:
		uint32_t GetRowCount( ) { return mRowCount; }
		uint32_t GetLowCount( ) { return mLowCount; }
	};

}

#endif

